﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CTP.CRM.Repository
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBaseRepository<T> where T : class, new()
    {
        Task<int> CountAsync(Expression<Func<T, bool>> whereExpression);

        List<T> GetList(Expression<Func<T, bool>> whereExpression);

        Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression);

        T GetFirst(Expression<Func<T, bool>> whereExpression);

        Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);

        T GetSingle(Expression<Func<T, bool>> whereExpression);

        Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression);

        Task<bool> InsertOrUpdateAsync(T data);

        Task<bool> InsertOrUpdateAsync(List<T> datas);

        bool Insert(T insertObj);

        Task<bool> InsertAsync(T insertObj);

        Task<bool> InsertRangeAsync(List<T> insertObjs);

        bool Update(T updateObj);

        Task<bool> UpdateAsync(T updateObj);

        Task<bool> UpdateAsync(Expression<Func<T, object>> columns, List<T> updateObj);

        Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
        bool UpdateRange(List<T> updateObjs);

        Task<bool> UpdateRangeAsync(List<T> updateObjs);

        Task<bool> DeleteAsync(List<T> entities);

        Task<bool> DeleteByIdsAsync(dynamic[] ids);

        Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression);
    }
}
